package com.example.demo.mapper;

import com.example.demo.entity.Comment;
import com.example.demo.entity.News;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NewsMapper {
    // 获取所有新闻
    @Select("SELECT * FROM news")
    List<News> getAllNews();

    // 根据ID获取新闻
    @Select("SELECT * FROM news WHERE id = #{id}")
    News getNewsById(Long id);

    // 插入新的新闻
    @Insert("INSERT INTO news(title, content, type, imageUrls) VALUES(#{title}, #{content}, #{type}, #{imageUrls})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertNews(News news);

    // 根据ID删除新闻
    @Delete("DELETE FROM news WHERE id = #{id}")
    void deleteNews(Long id);
}


